//package com.mccken.apt.kt;
//
//
//import com.huanliao.annotations.AppLikeAnnotation;
//import com.squareup.javapoet.ClassName;
//import com.squareup.javapoet.JavaFile;
//import com.squareup.javapoet.MethodSpec;
//import com.squareup.javapoet.TypeName;
//import com.squareup.javapoet.TypeSpec;
//
//import java.io.IOException;
//import java.util.LinkedHashSet;
//import java.util.Set;
//
//import javax.annotation.processing.AbstractProcessor;
//import javax.annotation.processing.Messager;
//import javax.annotation.processing.ProcessingEnvironment;
//import javax.annotation.processing.RoundEnvironment;
//import javax.annotation.processing.SupportedSourceVersion;
//import javax.lang.model.SourceVersion;
//import javax.lang.model.element.Element;
//import javax.lang.model.element.Modifier;
//import javax.lang.model.element.TypeElement;
//import javax.lang.model.type.TypeMirror;
//import javax.lang.model.util.ElementFilter;
//import javax.lang.model.util.Elements;
//import javax.tools.Diagnostic;
//
//@SupportedSourceVersion(SourceVersion.RELEASE_7)
//public class AppLikeProcessor extends AbstractProcessor {
//    private Elements elementTool = null;
//    private Messager messager;
//
//    public Set<String> getSupportedAnnotationTypes() {
//        LinkedHashSet types = new LinkedHashSet<String>();
//        types.add(AppLikeAnnotation.class.getCanonicalName());
//        return types;
//    }
//
//    @Override
//    public boolean process(Set<? extends TypeElement> set, RoundEnvironment roundEnvironment) {
//
//
//        messager.printMessage(Diagnostic.Kind.OTHER, ">>>>>>>>>>>>>>>>>>>>>> start...");
//
//        //使用该注解的元素集合
//        Set<? extends Element> elementsAnnotatedWith = roundEnvironment.getElementsAnnotatedWith(AppLikeAnnotation.class);
//
//        Set<TypeElement> typeElements = ElementFilter.typesIn(elementsAnnotatedWith);
//
//        for (TypeElement element : typeElements) {
//
//            //                messager.printMessage(Diagnostic.Kind.ERROR, ">>>>>>>>>>>>>>>>>>>>>> start..." + element.getSimpleName());
//            AppLikeAnnotation appLikeAnnotation = element.getAnnotation(AppLikeAnnotation.class);
//            boolean checkIsAppLikeSubClass = false;
//            for (TypeMirror typeMirror : element.getInterfaces()) {
//                if (typeMirror.toString().equals(Constants.APP_LIKE_IAPP_LIKE_INTERFACE)) {
//                    checkIsAppLikeSubClass = true;
//                    break;
//                }
//            }
//            if (!checkIsAppLikeSubClass) {
//                return false;
//            }
//
////                    messager.printMessage(Diagnostic.Kind.ERROR, element.getInterfaces().toString());
//            /**
//             * 定义了方法
//             */
//            MethodSpec getAppLikeRouter = MethodSpec.methodBuilder("getAppLikeRouter")
//                    .addModifiers(Modifier.PUBLIC)
//                    .returns(ClassName.get(String.class))
//                    .addStatement("return \"$N\"", String.valueOf(element.asType().toString()))
//                    .build();
//
//            TypeElement applikeFactoryInterfaceType = elementTool.getTypeElement(Constants.APP_LIKE_FACTORY_INTERFACE);
//            TypeMirror applikeFactoryInterMirror = applikeFactoryInterfaceType.asType();
//
//            /**
//             * 定义类
//             */
//            TypeSpec appLike = TypeSpec.classBuilder("$" + element.getSimpleName())
//                    .addModifiers(Modifier.PUBLIC, Modifier.FINAL)
//                    .addMethod(getAppLikeRouter)
//                    .addSuperinterface(TypeName.get(applikeFactoryInterMirror))
//                    .build();
//
//            /**
//             * 定义包名
//             */
//            JavaFile javaFile = JavaFile.builder(Constants.APP_LIKE_PACKAGE, appLike)
//                    .build();
//
//            try {
//                javaFile.writeTo(processingEnv.getFiler());
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
//        }
//
//        return false;
//    }
//
//
//    public void init(ProcessingEnvironment processingEnvironment) {
//        super.init(processingEnvironment);
//        elementTÎool = processingEnvironment.getElementUtils();
//        messager = processingEnvironment.getMessager();
//    }
//}
